/*
 *说明：类型值表 首页脚本
 *
 *@author liuxun 2012-03-07
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#importBtn').click(importOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
//function queryOperation(){
//	var params = opeForm.serializeObject();
//	grid.datagrid("options").pageNumber = 1;
//	grid.datagrid({
//		url: 'P_TYPE_VALUE!queryLicenseList.do',
//		queryParams: jQuery.extend({}, params, {'firstQuery': true})
//	});
//}

//查询操作
function queryOperation(){
	changeBastion_ip();
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//查看明细
function showInfo(key) {
	var url = 'P_TYPE_VALUE!showInfo.do?model.key=' + key;
	openWin(url,'pop'); 
}

//导入license 
function importOperation(){  
	var url = 'P_TYPE_VALUE!showImportLicense.do';
	openWin(url,'pop', 'A0', '500', '375');
}

//nscg 
function changeBastion_ip(){
	var options = { 
		url: 'P_TYPE_VALUE!showLicenseIndex.do',
		type: 'post',
		success: function(data){}
		}

	opeForm.ajaxSubmit(options);
}

//编辑类型值表
function editOperation(){  
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}

	var url = 'P_TYPE_VALUE!showEdit.do?model.key=' + rows[0].key;
	openWin(url,'pop');
}   

//删除类型值表
function deleteOperation() {
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要删除的记录!');	
		return;
	}

	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}
	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要删除选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'P_TYPE_VALUE!doDelete.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}